package com.cwj.film.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cwj.common.domain.film;
import com.cwj.common.utils.utils;
import com.cwj.film.service.inter.review;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

@Service
public class reviewImpl implements review {
    @Resource
    private com.cwj.film.dao.filmDao filmDao;
    @Resource
    private ServletContext servletContext;
    @Override
    public List<film> GetFilmListByType(String type,int size) throws InvocationTargetException, IllegalAccessException {
        QueryWrapper<film> queryWrapper = new QueryWrapper<>();
        List<film> films = filmDao.selectList(queryWrapper.select("type", "title","fid","release_date","location","film_source").eq("type", type).last("limit 0 , " + size));
        utils.GetFilmPictList(films,540,488,servletContext.getRealPath(""));

        return films;
    }

    @Override
    public Integer GetFilmSize(String type) {
        return filmDao.selectCount(new QueryWrapper<film>().eq("type", type));
    }

    @Override
    public List<film> GetFilmListByPageType(String type, int size, int page) throws InvocationTargetException, IllegalAccessException {
        QueryWrapper<film> queryWrapper = new QueryWrapper<>();
        int start = (page - 1) * size;
        List<film> films = filmDao.selectList( queryWrapper.eq("type", type).select("type", "title", "fid", "release_date", "location", "film_source").last("limit "+start+" , "+size));
        utils.GetFilmPictList(films,540,488,servletContext.getRealPath(""));
        return films;
    }
}
